/*
 * signal.cpp
 *
 *  Created on: Jul 13, 2013
 *      Author: m
 */

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "NewSemaphore.h"

using namespace ipc;

int main ( void )
{
    char mostrar[10240];
    //Semaphore sem;
    char option;

    Semaphore sem = Semaphore::get( "/tmp/mysem", 'a' );

    sprintf( mostrar,
            "SIGNAL: "
            "Enter 's' to signal or 'q' to quit.\n" );
    write( fileno(stdout), mostrar, strlen(mostrar) );

    while( std::cin >> option )
    {
        if ( option == 'q' || option == 'Q' )
        {
            break;
        }

        if ( option == 's' || option == 'S' )
        {
            sem.signal();

            sprintf( mostrar,
                    "SIGNAL: "
                    "signal sent.\n" );
            write( fileno(stdout), mostrar, strlen(mostrar) );
        }
    }

    return 0;
}

